package com.information.manage.basic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.model.query.AddRoleDepartmentQuery;
import com.information.manage.basic.model.query.AddRoleMenuQuery;
import com.information.manage.basic.model.query.FindRolePageQuery;
import com.information.manage.basic.model.query.SysRoleAddQuery;
import com.information.manage.basic.model.vo.RoleDepartmentAuthorityVO;
import com.information.manage.basic.model.vo.RoleMenuAuthorityVO;
import com.information.manage.basic.model.vo.SysRoleIdAndNameVO;
import com.information.manage.basic.model.vo.SysRolePageVO;
import com.information.manage.basic.common.result.Result;
import com.information.manage.basic.service.SysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("/add")
    @ApiOperation(value = "新增角色", notes = "新增角色")
    public Result<Integer> addRole(@RequestBody SysRoleAddQuery sysRoleAddQuery){
        return sysRoleService.addRole(sysRoleAddQuery);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    public Result<Boolean> deleteRole(@RequestBody List<Integer> roleIds){
        return Result.ok(sysRoleService.deleteRole(roleIds));
    }

    @GetMapping("/query/page")
    @ApiOperation(value = "分页查询角色", notes = "分页查询角色")
    public Result<Page<SysRolePageVO>> queryPageRole(FindRolePageQuery findRolePageQuery){
        return sysRoleService.queryPageRole(findRolePageQuery);
    }

    @GetMapping("/query/list")
    @ApiOperation(value = "角色集合", notes = "角色集合")
    public Result<List<SysRoleIdAndNameVO>> queryListRole(){
        return sysRoleService.queryListRole();
    }

    @PostMapping("/add/department")
    @ApiOperation(value = "添加角色的部门权限", notes = "添加角色的部门权限")
    public Result<Boolean> addRoleDepartment(@RequestBody AddRoleDepartmentQuery addRoleDepartmentQuery){
        return sysRoleService.addRoleDepartment(addRoleDepartmentQuery);
    }

    @PostMapping("/add/menu")
    @ApiOperation(value = "设置角色的菜单权限", notes = "设置角色的菜单权限")
    public Result<Boolean> addRoleMenu(@RequestBody AddRoleMenuQuery addRoleMenuQuery){
        return sysRoleService.addRoleMenu(addRoleMenuQuery);
    }

    @GetMapping("/inside/add/admin/menu")
    @ApiOperation(value = "admin添加菜单权限", notes = "admin添加菜单权限")
    public Result<Boolean> addAdminMenu(Integer adminRoleId){
        return sysRoleService.addAdminMenu(adminRoleId);
    }

    @GetMapping("/query/department/by/role")
    @ApiOperation(value = "查询角色部门权限", notes = "查询角色部门权限")
    public Result<List<RoleDepartmentAuthorityVO>> queryDepartment(Integer roleId, Integer typeCollection){
        return sysRoleService.queryDepartment(roleId, typeCollection);
    }

    @GetMapping("/query/menu")
    @ApiOperation(value = "查询角色的菜单权限", notes = "查询角色的菜单权限")
    public Result<List<RoleMenuAuthorityVO>> queryRoleMenu(Integer roleId){
        return sysRoleService.queryRoleMenu(roleId);
    }

}
